import _thread
from time import sleep, ctime
loops=[4,2]
def loop(nloop,sec,lock):
	print('开始循环',nloop,'在：',ctime())
	sleep(sec)
	print('循环',nloop ,'结束于：',ctime())
	lock.release()
def main():
	print('开始于：',ctime())
	locks=[]
	nloops=range(len(loops))
	for i in nloops:
		lock=_thread.allocate_lock()
		lock.acquire()
		locks.append(lock)
	for i in nloops:
		_thread.start_new_thread(loop,(i,loops[i],locks[i]))
	for i in nloops:
		while locks[i].locked():
			pass
	print('所有的任务完成于：',ctime())
if __name__ =='__main__':
	main()